package net.hn.hnms.biz.plan.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import net.hn.hnms.biz.plan.domain.PlanMining;
import net.hn.hnms.biz.plan.vo.PlanMiningVO;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.math.BigDecimal;

public interface PlanMiningMapper extends BaseMapper<PlanMining> {


    @Select("<script>" +
            " select count(mining_plan_name) as totalPlan, " +
            " sum(mining_plan_footage) as totalMiningLength, " +
            " min(plan_start_date) as planStartDate, " +
            " max(plan_end_date) as planEndDate " +
            " from plan_mining where del_flag ='0' and mine_code =#{mineCode} " +
            "</script>")
    PlanMiningVO selectTotalByMineCode(@Param("mineCode") String mineCode);

    @Select("<script>" +
            " select count(mining_plan_name) as totalPlan, " +
            " sum(mining_plan_footage) as totalMiningLength, " +
            " min(plan_start_date) as planStartDate, " +
            " max(plan_end_date) as planEndDate " +
            " from plan_mining where del_flag ='0' and company_code =#{mineCode} " +
            "</script>")
    PlanMiningVO selectExecutionOtherTotalByCompanyCodeOrName(@Param("mineCode") String mineCode);


    @Select("<script>" +
            " select mining_plan_footage as miningPlanFootage from plan_mining pm where del_flag='0' and  " +
            "  pm.mining_plan_type='1' and mining_face_id =#{faceId} and  plan_start_date <![CDATA[ = ]]> to_date( #{weekTimeStart}, 'YYYY-MM-DD' ) and plan_end_date <![CDATA[ = ]]> to_date( #{weekTimeEnd}, 'YYYY-MM-DD' )   " +
            "</script>")
    PlanMiningVO selectMiningPlanFootageByMineCode(@Param("faceId") String faceId,@Param("weekTimeStart") String weekTimeStart,@Param("weekTimeEnd") String weekTimeEnd);


    @Select("<script>" +"select sum(t1.mining_plan_footage) planoutput from (select mining_plan_footage,to_char(plan_start_date,'YYYYMM') monthdate from plan_mining where del_flag = '0'  and mining_plan_type = '1' \n" +
            "and mine_code=#{code} and mining_face_id = #{faceId}\n" +
            "and to_char(plan_start_date,'YYYYMM') =  to_char(to_date(#{date}, 'YYYY-MM-DD'), 'YYYYMM')) t1 GROUP BY t1.monthdate order by t1.monthdate asc\n"+"</script>" )
    BigDecimal planMonth(@Param("faceId") String faceId, @Param("code") String code,@Param("date") String date );


    @Select("<script>"
            +" select sum(t1.mining_plan_footage) planoutput from (select mining_plan_footage,to_char(plan_start_date,'YYYYMM') monthdate from plan_mining where del_flag = '0'  and mining_plan_type = '1' \n" +
            "and mine_code=#{code} and mining_face_id =  #{faceId}\n" +
            "and to_char(plan_start_date,'YYYY') =  to_char(to_date(#{date}, 'YYYY-MM-DD'), 'YYYYMM')) t1 \n "
            +"</script>" )
    BigDecimal planYear(@Param("faceId") String faceId, @Param("code") String code,@Param("date") String date  );


}
